//
//  TestTokenInfo.cpp
//  LightBasic
//
//  Created by Albert on 27/03/2011.
//  Copyright 2011 LightBasic Development Team. All rights reserved.
//

#include <boost/test/unit_test.hpp>
#include "TokenType.h"
#include "TokenInfo.h"
#include "StringRef.h"
using namespace lbc;



/// start suite
BOOST_AUTO_TEST_SUITE( TokenInfo )
    
    /**
     * Check GetTokenType method returns properly
     */
    BOOST_AUTO_TEST_CASE( GetTokenType )
    {
        #define KEYWORD(id, ...) \
            BOOST_CHECK( lbc::TokenInfo::GetTokenType(#id, TknInvalid) == TknKw##id );
        #define OPERATOR_ALIAS(id, op, ...) \
            BOOST_CHECK( lbc::TokenInfo::GetTokenType(#id, TknInvalid) == TknOp##op );
        #include "TokenInfo.def.h"
    }


    /**
     * Check GetTokenType method returns properly
     */
    BOOST_AUTO_TEST_CASE( GetTokenName )
    {
        #define TOKEN(id, _str,...) \
            BOOST_CHECK( lbc::TokenInfo::GetTokenName( Tkn##id ) == _str );
        #define OPERATOR(id, _str, ...) \
            BOOST_CHECK( lbc::TokenInfo::GetTokenName( TknOp##id ) == _str );
        #define KEYWORD(id, ...) \
            BOOST_CHECK( lbc::TokenInfo::GetTokenName( TknKw##id ) == #id );
        #include "TokenInfo.def.h"
    }

    /**
     * Check GetTokenType method returns properly
     */
    BOOST_AUTO_TEST_CASE( GetOperatorPrecedence )
    {
        #define OPERATOR(id, str, lit, prec, ...) \
            BOOST_CHECK( lbc::TokenInfo::GetOperatorPrecedence( TknOp##id ) == prec );
        #include "TokenInfo.def.h"
    }

    /**
     * Test token type query
     */
    BOOST_AUTO_TEST_CASE( TestTypeQueries )
    {
        const int RTL     = 1 << 0;
        const int UNARY   = 1 << 1;
        const int BINARY  = 1 << 2;
        #define TEST_OP(type, isTk, isOp, isKw, isOpBin, isOpUn, isOpRtl)     \
            BOOST_CHECK( lbc::TokenInfo::IsOperator(type)       == isOp    ); \
            BOOST_CHECK( lbc::TokenInfo::IsBinaryOperator(type) == isOpBin ); \
            BOOST_CHECK( lbc::TokenInfo::IsUnaryOperator(type)  == isOpUn  ); \
            BOOST_CHECK( lbc::TokenInfo::IsRtlOperator(type)    == isOpRtl ); \
            BOOST_CHECK( lbc::TokenInfo::IsKeyword(type)        == isKw    ); \
            BOOST_CHECK( lbc::TokenInfo::IsToken(type)          == isTk    );
        #define TOKEN(id, ...)                      TEST_OP(Tkn##id,   true,  false, false, false, false, false);
        #define OPERATOR(id, str, lit, prec, flags) TEST_OP(TknOp##id, false, true,  false, (((flags) & BINARY) != 0), (((flags) & UNARY) != 0), (((flags) & RTL) != 0));
        #define KEYWORD(id, ...)                    TEST_OP(TknKw##id, false, false, true, false, false, false);
        #include "TokenInfo.def.h"
    }

BOOST_AUTO_TEST_SUITE_END()
/// end suite
